package org.swingplus.core.context;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.swingplus.core.factory.BeanFactory;
import org.swingplus.core.factory.ObjectFactory;
import org.swingplus.core.factory.WidgetFactroy;
import org.swingplus.core.scanner.WidgetScan;

public class ApplicationContext{
	
    private static final Logger logger= LoggerFactory.getLogger(ApplicationContext.class);
	private static Map<String,Object> container =new HashMap<>();


	/** Cache of singleton objects: bean name --> bean instance */
	private final Map<String, Object> singletonObjects = new ConcurrentHashMap<String, Object>(256);

	/** Cache of singleton factories: bean name --> ObjectFactory */
	private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<String, ObjectFactory<?>>(16);

	/** Cache of early singleton objects: bean name --> bean instance */
	private final Map<String, Object> earlySingletonObjects = new HashMap<String, Object>(16);


	public static boolean isExistsKey(String bean) {
		return container.containsKey(bean);
	}


	public static Object getBean(String bean) {
		return container.get(bean);
	}

	public static Object getBean(String bean,Class clazz) {
		return container.get(bean);
	}
//
	public static Object getBean(String bean,String clazz) {
		return container.get(bean);
	}
	
	public static Object getBean(String bean,String id,String scope) {
		Object obj=WidgetFactroy.create(bean,id, scope);
//		if(null!=obj) {
			return obj;
//		}else {
//			
//		}
//		
		
//		return container.get(bean);
		
	}
	public static void setBean(String bean,Object obj) {
		
		 container.put(bean,obj);
	}

}
